package com.ooono.factorytest.data;

import android.annotation.SuppressLint;
import android.content.Context;

import com.ooono.factorytest.AutoTestMainActivity;
import com.ooono.factorytest.R;
import com.ooono.factorytest.items.BatteryTestActivity;
import com.ooono.factorytest.items.BluetoothTestActivity;
import com.ooono.factorytest.items.FactoryResetActivity;
import com.ooono.factorytest.items.GSensorTestActivity;
import com.ooono.factorytest.items.GpsCameraTestActivity;
import com.ooono.factorytest.items.GyroscopeTestActivity;
import com.ooono.factorytest.items.MainCameraTestActivity;
import com.ooono.factorytest.items.DisplayTestActivity;
import com.ooono.factorytest.items.InfoTestActivity;
import com.ooono.factorytest.items.KeyTestActivity;
import com.ooono.factorytest.items.LedTestActivity;
import com.ooono.factorytest.items.MainMicTestActivity;
import com.ooono.factorytest.items.NfcTestActivity;
import com.ooono.factorytest.items.PhotosensitiveTestActivity;
import com.ooono.factorytest.items.RebootTestActivity;
import com.ooono.factorytest.items.SimTestActivity;
import com.ooono.factorytest.items.StorageTestActivity;
import com.ooono.factorytest.items.SpeakerTestActivity;
import com.ooono.factorytest.items.GpsTestActivity;
import com.ooono.factorytest.items.SubCameraTestActivity;
import com.ooono.factorytest.items.SubMicTestActivity;
import com.ooono.factorytest.items.ThirdCameraTestActivity;
import com.ooono.factorytest.items.TouchTestActivity;
import com.ooono.factorytest.items.VibratorTestActivity;
import com.ooono.factorytest.items.WifiTestActivity;
import com.ooono.factorytest.model.TestItem;
import com.ooono.factorytest.utils.SPUtils;

import java.util.ArrayList;
import java.util.List;

import mcs8.mdm.PolicyManager;

public class TestItemManager {

    @SuppressLint("StaticFieldLeak")
    private static TestItemManager sInstance = null;
    @SuppressLint("StaticFieldLeak")
    private static Context sContext;
    private final List<TestItem> mTestItems = new ArrayList<>();

    public static final String TEST_ITEM_INFO_KEY = "info";
    public static final String TEST_ITEM_WIFI_KEY = "wifi";
    public static final String TEST_ITEM_BT_KEY = "bt";
    public static final String TEST_ITEM_DISPLAY_KEY = "display";
    public static final String TEST_ITEM_SPEAKER_KEY = "speaker";
    public static final String TEST_ITEM_KEY_KEY = "key";

    private TestItemManager(Context context) {
        sContext = context;
    }

    public static TestItemManager getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new TestItemManager(context);
        }
        return sInstance;
    }


    public List<TestItem> loadTestItemsActivity() {
        mTestItems.clear();

        SPUtils spUtils = SPUtils.get(sContext);
        mTestItems.add(new TestItem(TEST_ITEM_INFO_KEY, sContext.getString(R.string.test_item_info), InfoTestActivity.class, spUtils.getData(TEST_ITEM_INFO_KEY, 0)));

        // 全自动测试项（自动测试项放前面）
        mTestItems.add(new TestItem(TEST_ITEM_WIFI_KEY, sContext.getString(R.string.test_item_wifi), WifiTestActivity.class, spUtils.getData(TEST_ITEM_WIFI_KEY, 0)));
        mTestItems.add(new TestItem(TEST_ITEM_BT_KEY, sContext.getString(R.string.test_item_bluetooth), BluetoothTestActivity.class, spUtils.getData(TEST_ITEM_BT_KEY, 0)));

        // 半自动测试项

        // 人工测试项（人工测试项放后面）
        mTestItems.add(new TestItem(TEST_ITEM_KEY_KEY, sContext.getString(R.string.test_item_key), KeyTestActivity.class, spUtils.getData(TEST_ITEM_KEY_KEY, 0)));
        mTestItems.add(new TestItem(TEST_ITEM_DISPLAY_KEY, sContext.getString(R.string.test_item_display), DisplayTestActivity.class, spUtils.getData(TEST_ITEM_DISPLAY_KEY, 0)));
        mTestItems.add(new TestItem(TEST_ITEM_SPEAKER_KEY, sContext.getString(R.string.test_item_speaker), SpeakerTestActivity.class, spUtils.getData(TEST_ITEM_SPEAKER_KEY, 0)));
        mTestItems.add(new TestItem(PhotosensitiveTestActivity.KEY, sContext.getString(R.string.test_item_photosensitive), PhotosensitiveTestActivity.class, spUtils.getData(PhotosensitiveTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(VibratorTestActivity.KEY, sContext.getString(R.string.test_item_vibrator), VibratorTestActivity.class, spUtils.getData(VibratorTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(MainCameraTestActivity.KEY, sContext.getString(R.string.test_item_main_camera), MainCameraTestActivity.class, spUtils.getData(MainCameraTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(SubCameraTestActivity.KEY, sContext.getString(R.string.test_item_sub_camera), SubCameraTestActivity.class, spUtils.getData(SubCameraTestActivity.KEY, 0)));
        if (!"DSJ-V1PRO".equals(PolicyManager.getInternalProductModel())) {
            mTestItems.add(new TestItem(ThirdCameraTestActivity.KEY, sContext.getString(R.string.test_item_third_camera), ThirdCameraTestActivity.class, spUtils.getData(ThirdCameraTestActivity.KEY, 0)));
        }
        mTestItems.add(new TestItem(LedTestActivity.KEY, sContext.getString(R.string.test_item_led), LedTestActivity.class, spUtils.getData(LedTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(MainMicTestActivity.KEY, sContext.getString(R.string.test_item_main_mic), MainMicTestActivity.class, spUtils.getData(MainMicTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(GyroscopeTestActivity.KEY, sContext.getString(R.string.test_item_main_gyroscope), GyroscopeTestActivity.class, spUtils.getData(GyroscopeTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(GSensorTestActivity.KEY, sContext.getString(R.string.test_item_main_g_sensor), GSensorTestActivity.class, spUtils.getData(GSensorTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(SubMicTestActivity.KEY, sContext.getString(R.string.test_item_sub_mic), SubMicTestActivity.class, spUtils.getData(SubMicTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(StorageTestActivity.KEY, sContext.getString(R.string.test_item_storage), StorageTestActivity.class, spUtils.getData(StorageTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(SimTestActivity.KEY, sContext.getString(R.string.test_item_sim), SimTestActivity.class, spUtils.getData(SimTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(BatteryTestActivity.KEY, sContext.getString(R.string.test_item_battery), BatteryTestActivity.class, spUtils.getData(BatteryTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(TouchTestActivity.KEY, sContext.getString(R.string.test_item_touch), TouchTestActivity.class, spUtils.getData(TouchTestActivity.KEY, 0)));
        if ("1".equals(PolicyManager.getSystemProperties("ro.beidou.chip", "0"))) {
            mTestItems.add(new TestItem(GpsCameraTestActivity.KEY, sContext.getString(R.string.test_item_gps_camera), GpsCameraTestActivity.class, spUtils.getData(GpsCameraTestActivity.KEY, 0)));
        } else {
            mTestItems.add(new TestItem(GpsTestActivity.KEY, sContext.getString(R.string.test_item_gps), GpsTestActivity.class, spUtils.getData(GpsTestActivity.KEY, 0)));
        }
        mTestItems.add(new TestItem(NfcTestActivity.KEY, sContext.getString(R.string.test_item_nfc), NfcTestActivity.class, spUtils.getData(NfcTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(RebootTestActivity.KEY, sContext.getString(R.string.test_item_reboot), RebootTestActivity.class, spUtils.getData(RebootTestActivity.KEY, 0)));
        mTestItems.add(new TestItem(FactoryResetActivity.KEY, sContext.getString(R.string.test_item_factory_reset), FactoryResetActivity.class, spUtils.getData(FactoryResetActivity.KEY, 0)));
        mTestItems.add(new TestItem("auto", sContext.getString(R.string.test_item_auto), AutoTestMainActivity.class, spUtils.getData("auto", 0)));
        return mTestItems;
    }

}
